gh-86533: Restore os.makedirs() ability to apply *mode* recursively#150011
Conversation
Allow os.makedirs() to apply the *mode* argument to any intermediate directories that are created.
- Replace recursive_mode with more intuitive parent_mode parameter - parent_mode=None (default): intermediate dirs use default permissions - parent_mode=<mode>: intermediate dirs use specified permissions - parent_mode=mode: matches Python 3.6 behavior - Update documentation with version markers and usage examples - Add comprehensive test coverage with separate focused test functions - Fix test permissions to avoid cleanup issues (0o555 → 0o705) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add parent_mode parameter to Path.mkdir() for specifying intermediate directory permissions when parents=True - Maintain pathlib's independence by using recursive implementation rather than delegating to os.makedirs - Add comprehensive tests including umask behavior verification - Update documentation and whatsnew entries - Provides consistency with os.makedirs parent_mode parameter 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Use st_mode & 0o777 masking instead of stat.S_IMODE() to ignore filesystem-specific bits like setgid, matching the approach used in os.makedirs tests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
|
@gpshead Hi! This is the PR we talked abut with the conflict fixed. |
Documentation build overview
7 files changed ·
|
…dir tests Address review feedback on the parent_mode addition: - Docs (os.makedirs, Path.mkdir): state that parent_mode, like mode, is combined with the process umask; it does not bypass it. - Mark the parameter as added in 3.15 (approved for the 3.15 backport) instead of "next", which on main would resolve to 3.16. - Replace the misleading "parent_mode overrides umask" test with one that verifies umask IS applied to parent_mode (0o777 + umask 0o022 -> 0o755); add the matching os.makedirs test. - Make MakedirTests cleanup name-agnostic and robust via os_helper.rmtree() instead of a hard-coded dir1/.../dir6 walk. - Align the new test_os skips with the pathlib tests (Emscripten/WASI/Android); restore the original 0o555 case in test_mode. - Use os_helper.temp_umask() in the pathlib tests instead of a manual os.umask() try/finally.
|
GH-150036 is a backport of this pull request to the 3.15 branch. |
|
|
|
…ively (GH-150011) (#150036) bpo-42367: Restore os.makedirs() and pathlib.mkdir() ability to apply *mode* recursively via a new parent_mode= keyword argument. (cherry picked from commit 9770e32) + Make Path.mkdir parent_mode tests umask-independent test_mkdir_with_parent_mode, test_mkdir_parent_mode_deep_hierarchy and test_mkdir_parent_mode_same_as_mode assert exact directory mode bits but did not pin the process umask. On buildbots running with a restrictive umask (e.g. 0o077) the 0o755 leaf was masked down to 0o700, failing the assertions. Wrap them in os_helper.temp_umask(0o022), matching the other umask-aware mkdir tests in this file. --------- Co-authored-by: nessita <124304+nessita@users.noreply.github.com> Co-authored-by: Zackery Spytz <zspytz@gmail.com> Co-authored-by: Erlend E. Aasland <erlend@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Uh oh!
There was an error while loading. Please reload this page.